//
//  SDGuideCell.m
//  SuperDoctor
//
//  Created by 龚睿 on 16/7/11.
//  Copyright © 2016年 SD. All rights reserved.
//

#import "SDGuideCell.h"
#import "SDGuideViewController.h"
#import "SDAppDelegate.h"
#define Pig_Count 5


@implementation SDGuideCell

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        // MARK: -添加按钮 并且设置监听点击事件
        
        //    1创建按钮
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        self.experienceBtn = btn;
        //    2设置背景图片
        [btn setBackgroundImage:[UIImage imageNamed:@"fengexian"] forState:UIControlStateNormal];
        [btn setTitle:@"蜀黍 约吗" forState:UIControlStateNormal];
        [btn sizeToFit];
        
        //  添加
        [self.contentView addSubview:btn];
        
        //    约束
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left).offset(15);
            make.top.mas_equalTo(self.mas_top).offset(30);
            
        }];
        
        //    添加监听点击方法
        [btn addTarget:self action:@selector(didClickIntoBtn) forControlEvents: UIControlEventTouchUpInside];
        
        //    创建pageControl
        UIPageControl *pageControl = [[UIPageControl alloc] init];
        [self.contentView addSubview:pageControl];
        
        //    设置pageControl
        int colorNum = arc4random_uniform(100);
        
        pageControl.numberOfPages = Pig_Count;
        pageControl.currentPage = 0;
        pageControl.pageIndicatorTintColor = [UIColor redColor];
        pageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:colorNum/256.0 green:colorNum/256.0 blue:colorNum/256.0 alpha:1];
        [pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.mas_bottom).offset(-10);
            make.centerX.mas_equalTo(self.mas_centerX);
        }];
        

        self.pageControl = pageControl;
        
    }


    return self;
}

- (void)setCurrentPageIndex:(int)currentPageIndex{

    _currentPageIndex = currentPageIndex;
    
    self.pageControl.currentPage = _currentPageIndex;


}

#pragma mark
#pragma mark - 监听点击方法
- (void)didClickIntoBtn{

//    跳转到主界面
    [[[SDAppDelegate alloc]init]rootControllerChange];

}


@end
